package com.xuhuan.practice.utils;

import cn.hutool.core.map.MapUtil;
import java.util.Map;

/**
 * @author: huan.xu
 * @create: 2024/6/11 9:07
 * @description: 获取当前用户
 **/
public class CurrentUserUtil {

  private CurrentUserUtil() {
  }

  /**
   * 获取当前用户ID
   *
   * @return
   */
  public static Integer getCurrentUserId() {
    Map<String, Object> tokenDataMap = ThreadLocalUtil.get();
    return MapUtil.getInt(tokenDataMap, "id");
  }

  /**
   * 获取当前用户名
   *
   * @return
   */
  public static String getCurrentUserName() {
    Map<String, Object> tokenDataMap = ThreadLocalUtil.get();
    return MapUtil.getStr(tokenDataMap, "username");
  }
}
